package com.market.xg.gateway.utils;

import com.market.xg.common.starter.constant.TraceConstant;
import com.market.xg.common.starter.util.CommonUtils;
import org.springframework.http.server.reactive.ServerHttpRequest;

import java.util.UUID;

public class GatewayUtil {

  public static String getTraceId(ServerHttpRequest serverHttpRequest) {
    String traceId = serverHttpRequest.getHeaders().getFirst(TraceConstant.TRACE_ID_ON_HTTP_HEADER);
    return CommonUtils.isEmpty(traceId)
        ? UUID.randomUUID().toString().replaceAll("-", "")
        : traceId;
  }
}
